package com.neusoft.newelm.controller;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.newelm.bean.Food;
import com.neusoft.newelm.common.Pager;
import com.neusoft.newelm.service.FoodService;

/**
 * @RestController 的方法默认会返回json数据
 * 
 * @author chens
 *
 */
@RestController
@RequestMapping("/sys/food")
public class FoodController {
	private Logger logger = Logger.getLogger(AdminController.class);

	@Autowired
	private FoodService foodService;



	@RequestMapping("search")
	public Pager<Food> list(@RequestParam(value = "page", defaultValue = "1") Integer page,
			@RequestParam(value = "rows", defaultValue = "10") Integer size) {
		Pager<Food> pager = new Pager<>(page, size);

		logger.info(pager);

		int total = foodService.findTotal(pager);
		List<Food> list = foodService.findByPager(pager);

		pager.setRows(list);
		pager.setTotal(total);
		logger.info(pager);

		return pager;
	}

	

}
